
class SdkPatform
{
    constructor()
    {
        this.mId = 0
        //this.mData = {}
    }

    init(d)
    {
        if (this.requestInit)
        {
            this.requestInit(d)
        }
    }

    close()
    {
        if (this.requestClose)
        {
            this.requestClose()
        }
    }

    login(data, callback)
    {
        if (!this.requestLogin)
        {
            callback()

            return
        }

        ogre.onThirdPlatformLogin = (d)=>{

            this.onLogin(d)

            ogre.onThirdPlatformLogin = null

            if (this.mData)
            {
                this.mData.id = this.mId
            }
            
            callback(this.mData)
        }

        this.requestLogin(data)
    }

    logout(data, callback)
    {
        if (!this.requestLogout)
        {
            callback(true)

            return
        }

        ogre.onThirdPlatformLogout = (d)=>{

            ogre.onThirdPlatformLogout = null

            if (!this.onLogout || this.onLogout(d))
            {
                callback(true)
            }
            else
            {
                callback(false)
            }
        }

        this.requestLogout(data)
    }

    purchase(data, callback)
    {
        if (!this.requestPurchase)
        {
            callback()

            return
        }

        ogre.onThirdPlatformPurchase = (d)=>{

            ogre.onThirdPlatformPurchase = null

            callback(this.onPurchase ? this.onPurchase(d) : d)
        }

        this.requestPurchase(data)
    }

    share(data, callback)
    {
        if (!this.requestShare)
        {
            callback(false)

            return
        }

        ogre.onThirdPlatformShare = (d)=>{

            ogre.onThirdPlatformShare = null

            callback(d)
        }

        this.requestShare(data)
    }

    trackEvent(k)
    {

    }
    
    id()
    {
        return this.mId
    }

    dataBy(k)
    {
        if (this.mData)
        {
            return this.mData[k]
        }
        return null
    }

    enableAdvertising()
    {
        return false
    }

    requestAdvertising(i, callback)
    {
        
    }

    trackEvent(key, data)
    {

    }
}

export default SdkPatform
